package cn.agiledata.security.db.service;

import java.util.List;

import cn.agiledata.security.db.bean.EnctBean;

import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.MD5;
import cn.agiledata.bank.common.util.StringUtil;
/**
 * 
 * @author given
 *
 */
public class CommonJuggleServiceImpl implements ICommonJuggleService {
	private MD5 md5Service;

	public void setMd5Service(MD5 md5Service) {
		this.md5Service = md5Service;
	}

	/**
	 * 根据需要加密的字段的Bean构造加密字符串
	 * @param list
	 * @return
	 */
	public String parseEncrCode(EnctBean bean) {
		List list = bean.getNeedEnctList();
		StringBuffer encryptCode = new StringBuffer();
		if(list == null) {
			return "";
		} else {
			for(int i=0;i<list.size();i++) {
				String string = md5Service.getMD5ofStr(format((String)list.get(i))); //得到md5的加密值
				encryptCode.append(string);
			}
			return encryptCode.toString();
		}
	}

	
	/**
	 * 每个加密字符串加上一个;结尾
	 * @param string
	 * @return
	 */
	public String format(String string) {
		return string + Constant.STRING_SEMICOLON;
	}
}
